<template>
  <div>
    <van-nav-bar title="账号登录" left-arrow @click-left="$router.back()"/>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button block native-type="primary">登录</van-button>
      </div>
    </van-form>
    <div class="link">
      <router-link to="/register" class="link">还没有账号，去注册~</router-link>
    </div>
  </div>
</template>

<script>
import { login } from '@/api/user'
import { setToken } from '@/utils/storage'
// import axios from 'axios'
export default {
  name: 'login-page',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit (values) {
      // console.log('submit', values)
      const { data } = await login(values)
      // console.log(data)
      setToken(data.body.token)
      this.$router.push('/wode')
    }
  }
}
</script>

<style lang="less">
.link {
  text-align: center;
  color:#666
}
.van-nav-bar {
  position: relative;
  z-index: 1;
  line-height: 22px;
  text-align: center;
  background-color: #1cb676;
  -webkit-user-select: none;
  user-select: none;
  .van-icon {
    color: #fff;
  }
  .van-nav-bar__title {
    max-width: 60%;
    margin: 0 auto;
    color: #fff;
    font-weight: 500;
    font-size: 16px;
  }
}
.van-cell {
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    box-sizing: border-box;
    width: 100%;
    padding: 10px 16px;
    overflow: hidden;
    color: #323233;
    font-size: 14px;
    line-height: 50px;
    background-color: #fff;
}
.van-button--default {
  color: #fff;
  background-color: #1cb676;
  border: 1px solid #ebedf0;
}
</style>
